package com.crane.oss.sports;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.QueryPrescriptionClassInfoReq;
import com.crane.oss.xunfei.req.QueryPrescriptionClassStudentInfoReq;
import com.crane.oss.xunfei.req.QueryPrescriptionStudentInfoReq;
import com.crane.oss.xunfei.resp.*;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zx
 */
@Component
public class XunFeiPrescriptionApiService extends  XunFeiApiService{


    /**
     * 查询班级运动分析数据
     */
    public ApiSingleResponse<PrescriptionClassInfoResp> getPrescriptionClassInfo(QueryPrescriptionClassInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/class", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<PrescriptionClassInfoResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<PrescriptionClassInfoResp>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }
    /**
     * 查询班级BMI成绩分析
     */
    public ApiListResponse<PrescriptionBmiResp> getPrescriptionBmi(QueryPrescriptionClassInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/bmi", params);
        if (httpResult.isSuccess()) {
            ApiListResponse<PrescriptionBmiResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<PrescriptionBmiResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }
    /**
     * 查询班级项目成绩分析
     */
    public ApiListResponse<PrescriptionItemResp> getPrescriptionItem(QueryPrescriptionClassInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/item", params);
        if (httpResult.isSuccess()) {
            ApiListResponse<PrescriptionItemResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<PrescriptionItemResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }
    /**
     * 查询班级项目询学生列表
     */
    public ApiListResponse<PrescriptionClassStudentInfoResp> getPrescriptionStudent(QueryPrescriptionClassStudentInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/student", params);
        if (httpResult.isSuccess()) {
            ApiListResponse<PrescriptionClassStudentInfoResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<PrescriptionClassStudentInfoResp>>() {
            });
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 查询班级运动分析数据
     */
    public ApiSingleResponse<String> getPrescriptionClassInfo(QueryPrescriptionStudentInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/student/detail", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<String> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }


    /**
     * 查询处方班级成绩统计接口
     */
    public ApiSingleResponse<PrescriptionClassScoreStatisticResp> getPrescriptionClassScoreStatistic(QueryPrescriptionClassInfoReq request, String sid, String did, String uid) {
        Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult = HttpClientUtils.get(xunFeiAppConfig.getUrl() + "/prescription/info/mini/class/score/statistic", params);
        if (httpResult.isSuccess()) {
            ApiSingleResponse<PrescriptionClassScoreStatisticResp> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<PrescriptionClassScoreStatisticResp>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }


    public static void main(String[] args) {
        XunFeiPrescriptionApiService xunFeiApiService=new XunFeiPrescriptionApiService();
        QueryPrescriptionClassInfoReq queryPrescriptionClassInfoReq =new QueryPrescriptionClassInfoReq();
        queryPrescriptionClassInfoReq.setClassId("1");
        queryPrescriptionClassInfoReq.setSportCycleId("cycle-2021-2022");
        System.out.println(xunFeiApiService.getPrescriptionClassScoreStatistic(queryPrescriptionClassInfoReq,"87", null,"3"));


//        QueryPrescriptionClassStudentInfoReq queryTestCycleReq =new QueryPrescriptionClassStudentInfoReq();
//        queryTestCycleReq.setType(3);
//        queryTestCycleReq.setClassId("2");
//        queryTestCycleReq.setSportCycleId("cycle-2021-2022");
//        System.out.println(xunFeiApiService.getPrescriptionStudent(queryTestCycleReq,"87", null,"3"));


//        QueryPrescriptionStudentInfoReq queryPrescriptionStudentInfoReq=new QueryPrescriptionStudentInfoReq();
//        queryPrescriptionStudentInfoReq.setStudentId("1");
//        queryPrescriptionStudentInfoReq.setSportCycleId("cycle-2021-2022");
//        System.out.println(xunFeiApiService.getPrescriptionClassInfo(queryPrescriptionStudentInfoReq,"87", null,"3"));

    }
}
